import chooseMulDisease from "@/components/chooseDisease/chooseMulDisease";
import chooseMulDisease2 from "@/components/chooseDisease/chooseMulDisease2";
import uploadImg from "@/components/uploadImg"; //上传图片
export default {
    props: {
        form: {
            type: Object,
            default: () => {
                return {};
            },
        },
        selectDisease1: {
            type: Array,
            default: () => {
                return [];
            },
        },
        diseaseList1: {
            type: Array,
            default: () => {
                return [];
            },
        },
        doctorList1: {
            type: Array,
            default: () => {
                return [];
            },
        },
        form1: {
            type: Object,
            default: () => {
                return {};
            },
        },
        isReadyOnly: {
            type: Boolean,
            default: true,
        },
        title: {
            type: String,
            default: "",
        },
        type: {
            type: String,
            default: "",
        },
        from: {  //来源 系统、科室
            type: String,
            default: "",
        },
    },
    components: {
        chooseMulDisease,
        uploadImg,
        chooseMulDisease2
    },
    data() {
        return {
            selectDisease: [],
            diseaseList: [],//疾病列表
            doctorList: [],//医生列表
            editVisible: false,
            moreVisible: false,//其他弹框
            btnLoading: false, //按钮点击加载中
            pageTotal: 0,//数据总量
            tableData: [],
            query: {
                name: "",//搜索参数
                page: 1,//页码
                limit: 10,//页数
            },
        }
    },
    watch: {
        selectDisease1(val) {
            this.selectDisease = val;
        },
        diseaseList1(val) {
            this.diseaseList = val;
        },
        doctorList1(val) {
            this.doctorList = val;
        },

    },
    mounted() {
        this.selectDisease = this.selectDisease1;
        this.diseaseList = this.diseaseList1;
        this.doctorList = this.doctorList1;
    },
    methods: {
        initShow() {
            this.editVisible = true;
        },
        //富文本编辑器返回值
        editChange(val, name, form) {
            // this.form.desc = val;
            this.$set(this.form, name, val);
            if (val && this.$refs[form]) {
                this.$refs[form].validateField(name);
            }
        },
        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, "page", val);
            this.getList();
        },
        //switch切换事件
        handelChange(val, that, name) {
            if (val == true) {
                this.$set(that, name, 1);
            } else {
                this.$set(that, name, 0);
            }
        },
        //弹框关闭事件
        close() {
            this.form = {}; //清空数据
            this.form1 = {}; //清空数据
            this.type = "";
            this.$nextTick(() => {
                if (this.$refs.form) {
                    this.$refs.form.clearValidate();

                }
                if (this.$refs.Enditor) {
                    this.$refs.Enditor.clearVal();
                }
                if (this.$refs.diseaseBox) {
                    this.$refs.diseaseBox.reset()
                }
                if (this.$refs.doctorBox) {
                    this.$refs.doctorBox.reset()
                }

            })
            this.$emit("closeHandel");
        },
        //选择病种事件
        handelDisease(value, diseaseList, type) {
            this.$set(this.form, "diseaseCodes", value);
            if (this.diseaseList.length == 0) {
                this.diseaseList = diseaseList;
            }
            if (this.type == "add") {
                return;
            }
            if (value == this.selectDisease) {
                return;
            }
            if (this.selectDisease.length > value.length) {
                //删除
                this.selectDisease.filter((item) => {
                    if (!value.includes(item)) {
                        this.upDateDisease(item, "del", value, type);
                    }
                });
            } else {
                //新增
                value.filter((item) => {
                    if (!this.selectDisease.includes(item)) {
                        this.upDateDisease(item, "add", value, type);
                    }
                });
            }
        },
        //修改病种信息
        upDateDisease(item, type, value, types) {
            let data = {};
            if (types) {
                let code;
                this.selectDisease = value;
                this.diseaseList.find((list) => {
                    if (list.label === item) {
                        code = list.value;
                    }
                });
                data = {
                    code: code,
                    disease: item,
                };
            } else {
                let name;
                this.selectDisease = value;
                this.diseaseList.find((list) => {
                    if (list.value === item) {
                        name = list.label;
                    }
                });
                data = {
                    code: item,
                    disease: name,
                };
            }

            if (type == "del") {
                this.deleteDisease(data);
            }
            if (type == "add") {
                this.addDisease(data);
            }
        },
        //选择医生
        handelEvent(val, that, name) {
            this.$set(that, name, val);
        },
        //医生名称
        handelLabelEvent(val, that, name) {
            this.$set(that, name, val);
        },
        //图片上传成功路径
        updateImg(src, name) {
            this.$set(this.form, name, src);
        },
        //获取疾病列表
        handelDiseaseList(val) {
            this.diseaseList = val;
        },
        //获取医生列表
        handelDoctor(val) {
            this.doctorList = val;
        },
    }
}